package com.lin.manager.common.utils;

import java.util.Collection;

/**
 * @作者: 林江
 * @创建时间: 2024/4/27
 * @功能:
 */
public class StrUtils {

    public static boolean isEmpty(String str) {
        return isNull(str) || str.isEmpty();
    }

    public static <T> boolean isEmpty(Collection<T> collection) {
        return isNull(collection) || collection.size() == 0;
    }

    public static boolean isNull(Object object) {
        return object == null;
    }

    public static boolean isNotNull(Object object) {
        return !isNull(object);
    }


    /**
     * 大驼峰
     *
     * @return sys_user --> SysUser
     */
    public static String toBigCamel(String data, String symbol) {
        return toCamel(new StringBuilder(), capitalize(data), symbol);
    }

    /**
     * 小驼峰
     *
     * @return sys_user --> sysUser
     */
    public static String toSmallCamel(String data, String symbol) {
        return toCamel(new StringBuilder(), data, symbol);
    }

    /**
     * 驼峰式转换
     *
     * @param builder 容器
     * @param data    数据，如：sys_user
     * @param symbol  分隔符，如：_
     * @return
     */
    private static String toCamel(StringBuilder builder, String data, String symbol) {
        int i = data.indexOf(symbol);
        if (i > 0) {
            builder.append(data.substring(0, i));
            // 字符
            String firstChar = data.substring(i + 1, i + 2);
            toCamel(builder, data.substring(i).replace(symbol + firstChar, firstChar.toUpperCase()), symbol);
        } else {
            builder.append(data);
        }
        return builder.toString();
    }

    /**
     * 首字母大写
     *
     * @param data 转换数据，如 sysUser
     * @return 转换结果，SysUser
     */
    public static String capitalize(String data) {
        if (isEmpty(data)) {
            return data;
        }
        return Character.toUpperCase(data.charAt(0)) + data.substring(1);
    }
}
